package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;

    @Override

    /**
     * 新增线索跟进记录
     */
    public int add(ClueTrackRecordVo clueTrackRecordVo) {
        //创建线索跟进实体对象
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        //设置归属人和创建时间
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());
        //将前端传来的基本数据复制给线索跟进对象
        BeanUtils.copyProperties(clueTrackRecordVo, tbClueTrackRecord);

        //创建线索实体对象
        TbClue tbClue = new TbClue();
        //将将前端传来的基本数据复制给线索实体对象
        BeanUtils.copyProperties(clueTrackRecordVo, tbClue);
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbClue.setId(clueTrackRecordVo.getClueId());

        tbClueMapper.updateTbClue(tbClue);

        return tbClueTrackRecordMapper.add(tbClueTrackRecord);
    }

    /**
     * 查询线索跟进记录列表
     */
    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        return tbClueTrackRecordMapper.list(clueId);
    }
}
